//
//  CMBankLoginCtrl.m
//  CreditManger
//
//  Created by sky on 15/11/2.
//  Copyright © 2015年 jinxin. All rights reserved.
//

#import "CMBankLoginCtrl.h"
#import "CMBankCenterCtrl.h"
#import "CMBankRegistCtrl.h"

@interface CMBankLoginCtrl ()<UITextFieldDelegate>
{
    UITextField *_username;
    UITextField *_password;
    UIView *_bgview;
}

@end

@implementation CMBankLoginCtrl

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

-(void)doTouch:(UIGestureRecognizer *)sender
{
    [self.view endEditing:YES];
}

-(void)buildLayout{
    
    self.title = @"央行征信登录";
    
    _bgview = [[UIView alloc]initWithFrame:CGRectMake(0, 10, SCREEN_WIDTH, 80)];
    _bgview.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_bgview];
    
    [self makeLinewithRect:CGRectMake(0, 0, SCREEN_WIDTH, .5) Color:[LCCommon getColor:@"cccccc"] addview:_bgview];
    [self makeLinewithRect:CGRectMake(10, 40, SCREEN_WIDTH - 10, .5) Color:[LCCommon getColor:@"cccccc"] addview:_bgview];
    [self makeLinewithRect:CGRectMake(0, 80, SCREEN_WIDTH, .5) Color:[LCCommon getColor:@"cccccc"] addview:_bgview];
    _username = [self TextFieldWithRect:CGRectMake(10, 0, SCREEN_WIDTH, 40) leftImage:[UIImage imageNamed:@"login_username"] placeHold:@"输入账号" index:1];
    [_bgview addSubview:_username];
    
    _password = [self TextFieldWithRect:CGRectMake(10, 40, SCREEN_WIDTH, 40) leftImage:[UIImage imageNamed:@"login_password"] placeHold:@"输入密码" index:2];
    [_bgview addSubview:_password];
    
    
    UILabel *forget = [self LabelWithRect:CGRectMake(SCREEN_WIDTH - 40 - 10, 100, 40, 10) textColor:[LCCommon getColor:@"333333"] textstr:@"忘记密码" textfont:10 textstyle:NSTextAlignmentCenter];
    forget.userInteractionEnabled = YES;
    [self.view addSubview:forget];
    
    UITapGestureRecognizer *fgttap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(forgetpress)];
    [forget addGestureRecognizer:fgttap];
    
    UIButton *loginbtn = [[UIButton alloc]initWithFrame:CGRectMake(10, forget.origin.y + 10 + 10, SCREEN_WIDTH - 20, 40)];
    loginbtn.backgroundColor = [LCCommon getColor:@"f7514a"];
    [loginbtn setTitle:@"登录" forState:UIControlStateNormal];
    [loginbtn setTitleColor:[UIColor colorWithWhite:1.0 alpha:0.2] forState:UIControlStateNormal];
    loginbtn.titleLabel.font = [UIFont systemFontOfSize:15];
    loginbtn.layer.cornerRadius = 2.5;
    [loginbtn addTarget:self action:@selector(loginpress) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:loginbtn];
    
    UILabel *kaitong = [self LabelWithRect:CGRectMake(SCREEN_WIDTH/2 - 45, loginbtn.origin.y + 40 + 15, 90, 10) textColor:[LCCommon getColor:@"333333"] textstr:@"还没开通?立即开通" textfont:10 textstyle:NSTextAlignmentCenter];
    kaitong.userInteractionEnabled = YES;
    
    NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:kaitong.text];
    [noteStr addAttribute:NSForegroundColorAttributeName value:[LCCommon getColor:@"33CC99"] range:NSMakeRange(5, 4)];
    [kaitong setAttributedText:noteStr] ;
    [self.view addSubview:kaitong];
    UITapGestureRecognizer *res = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(kaitongpress)];
    [kaitong addGestureRecognizer:res];
    
    [self addTap];
    
}


#pragma mark - kaitongpress

-(void)kaitongpress{
    LLog(@"kaitongpress");
    CMBankRegistCtrl* bankRegistVC =[[CMBankRegistCtrl alloc] init];
    [self.navigationController pushViewController:bankRegistVC animated:YES];
}


#pragma mark - loginpress

-(void)loginpress{
    LLog(@"loginpress");
    CMBankCenterCtrl *bankcenter = [[CMBankCenterCtrl alloc]init];
    [self.navigationController pushViewController:bankcenter animated:YES];
}


#pragma mark - forgetpress

-(void)forgetpress{
    LLog(@"forgetpress");
}


#pragma mark - MakeText

-(UITextField *)TextFieldWithRect:(CGRect)rect leftImage:(UIImage *)image placeHold:(NSString *)placeHold index:(NSInteger)index
{
    UITextField *text = [[UITextField alloc] initWithFrame:rect];
    text.placeholder = placeHold;
    text.backgroundColor = [UIColor clearColor];
    text.delegate = self;
    text.clearButtonMode = YES;
    text.textColor = [LCCommon getColor:@"333333"];
    text.font = [UIFont systemFontOfSize:12];
    [text setFont:[UIFont systemFontOfSize:12]];
    [text setValue:[LCCommon getColor:@"cccccc"] forKeyPath:@"_placeholderLabel.textColor"];
    
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, image.size.width + 34/2, rect.size.height)];
    view.backgroundColor = [UIColor clearColor];
    CGFloat width = image.size.width;
    
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, (view.height - width)/2, width, width)];
    
    if (index == 0) {
        imageView.frame = CGRectMake(0, view.height - 10 - width, width, width);
    }
//    UIView *line = [[UIView alloc]initWithFrame:CGRectMake(text.origin.x, text.origin.y + text.size.height + .5, text.size.width, .5)];
//    line.backgroundColor = [LCCommon getColor:@"cccccc"];
//    [_bgview addSubview:line];
    
    imageView.image = image;
    [view addSubview:imageView];
    text.leftView = view;
    text.leftViewMode = UITextFieldViewModeAlways;
    view = nil;
    imageView = nil;
    
    return text;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)makeLinewithRect:(CGRect)rect Color:(UIColor *)color addview:(UIView *)vi{
    UIView *line = [[UIView alloc]initWithFrame:rect];
    line.backgroundColor = color;
    [vi addSubview:line];
}


-(UILabel *)LabelWithRect:(CGRect)rect textColor:(UIColor *)color textstr:(NSString *)str textfont:(int)font textstyle:(NSTextAlignment)aligment{
    UILabel *label = [[UILabel alloc] initWithFrame:rect];
    label.textColor = color;
    label.text = str;
    label.font = [UIFont systemFontOfSize:font];
    label.textAlignment = aligment;
    label.numberOfLines = 0;
    return label;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
